package com.jeeplus.modules.flowable.listener;

import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.ExecutionListener;
import org.flowable.engine.runtime.ProcessInstance;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.jeeplus.modules.sys.entity.User;
import com.jeeplus.modules.sys.service.OfficeService;
import com.jeeplus.modules.sys.service.UserService;

@Component("startProcessListener")
public class StartProcessListener implements ExecutionListener {

	private static final long serialVersionUID = -1764623554723851394L;
	
	@Autowired
    private UserService userService;
	
	@Autowired
	private OfficeService officeService;
	

	public void notify(DelegateExecution delegateExecution) {

        String eventName = delegateExecution.getEventName();
       

        if ("start".equals(eventName)) {
        	ProcessInstance processInstance= (ProcessInstance) delegateExecution.getParent();
        	User startUser=userService.get(processInstance.getStartUserId());
        	String officeId=startUser.getOffice().getId();
        	delegateExecution.setVariable("officeId", officeId);
            System.out.println("Process Variable Init");
        }
    }
}
